home *** CD-ROM | disk | FTP | other *** search
/ Aminet 24 / Aminet 24 (1998)(GTI - Schatztruhe)[!][Apr 1998].iso / Aminet / dev / c / cxref_1_4a.lha / cxref-cc < prev    next >
Text File  |  1997-06-22  |  3KB  |  134 lines

  1. #!/bin/sh
  2.  
  3. # $Header: /home/amb/cxref/RCS/cxref-cc 1.1 1997/06/22 10:04:59 amb Exp $
  4. #
  5. # C Cross Referencing & Documentation tool. Version 1.4.
  6. #
  7. # C compiler replacement to compile program and cross reference it.
  8. #
  9. # Written by Andrew M. Bishop
  10. #
  11. # This file Copyright 1997 Andrew M. Bishop
  12. # It may be distributed under the GNU Public License, version 2, or
  13. # any higher version.  See section COPYING of the GNU Public license
  14. # for conditions under which this file may be redistributed.
  15. #
  16.  
  17. # Print a usage statement.
  18.  
  19. if [ $# = 0 ]; then
  20.  
  21.     echo 'Usage: cxref-cc filename [CC-arguments]'
  22.     echo ''
  23.     echo 'filename        : The name of the file to compile and cross reference.'
  24.     echo 'CC-arguments    : Any number of arguments to the C compiler.'
  25.     echo ''
  26.     echo 'The C compiler is called first, and if this succeeds then cxref is called.'
  27.     echo 'You require a .cxref file to contain the cxref options.'
  28.     exit 1
  29.  
  30. fi
  31.  
  32. # Check for a .cxref file.
  33.  
  34. if [ ! -r .cxref ]; then
  35.  
  36.     echo 'cxref-cc: Error a .cxref file is required to use cxref-cc.'
  37.     echo '          If you do not need any arguments an empty file will work.'
  38.     exit 1
  39.  
  40. fi
  41.  
  42. # The variables that we are going to use.
  43.  
  44. if [ "x$CXREFCC" = x ]; then
  45.     if [ "x$CC" = x ]; then
  46.         CXREFCC=gcc
  47.     else
  48.         CXREFCC=`echo $CC | cut -d' ' -f1`
  49.         if [ `basename $CXREFCC` = cxref-cc ]; then
  50.             echo 'cxref-cc: Warning the CC variable points to cxref-cc, set CXREFCC instead.'
  51.             CXREFCC=gcc
  52.         fi
  53.     fi
  54. fi
  55.  
  56. CXREF=cxref
  57.  
  58. FILE=
  59.  
  60. CXREFFLAGS=
  61.  
  62. # Call the C compiler
  63.  
  64. $CXREFCC "$@"
  65.  
  66. if [ ! $? = 0 ]; then
  67.  
  68.     echo 'cxref-cc: The C compiler failed with an error status.'
  69.     exit 1
  70.  
  71. fi
  72.  
  73. # Loop over the arguments and sort them out.
  74.  
  75. # Note: Need to be careful because "-DFOO=BAR BAR" loses its quotes on parameter
  76. #       expansion, but must be passed to cxref as a single word.  We need to use
  77. #       a word separator since there are no arrays, so we use ^M.
  78.  
  79. while [ ! $# = 0 ]; do
  80.  
  81.     case $1 in
  82.  
  83.         # The arguments to keep
  84.  
  85.         -D)
  86.             CXREFFLAGS="$CXREFFLAGS$1$2"; shift;;
  87.         -D*)
  88.             CXREFFLAGS="$CXREFFLAGS$1";;
  89.  
  90.         -U)
  91.             CXREFFLAGS="$CXREFFLAGS$1$2"; shift;;
  92.         -U*)
  93.             CXREFFLAGS="$CXREFFLAGS$1";;
  94.  
  95.         -I)
  96.             CXREFFLAGS="$CXREFFLAGS$1$2"; shift;;
  97.         -I*)
  98.             CXREFFLAGS="$CXREFFLAGS$1";;
  99.  
  100.         # The filename (perhaps)
  101.  
  102.         *.c)
  103.             if [ "x$FILE" = x -a -r $1 ]; then
  104.                 FILE=$1;
  105.             fi;;
  106.  
  107.         # The arguments to throw away
  108.  
  109.         *)
  110.             ;;
  111.  
  112.     esac
  113.     shift
  114.  
  115. done
  116.  
  117. # Check that a file was specified
  118.  
  119. if [ "x$FILE" = x ]; then
  120.  
  121.     echo 'cxref-cc : Warning no file specified on the command line'
  122.     exit 0
  123.  
  124. fi
  125.  
  126. # Call cxref
  127.  
  128. # Note: We are using ^M as the word separator, as detailed above.
  129.  
  130. IFS=
  131. export IFS
  132.  
  133. $CXREF$FILE$CXREFFLAGS
  134.